
import 'package:carousel_slider/carousel_slider.dart';
import 'package:niuniu/common/constant/AssetsImage.dart';
import 'package:niuniu/common/model/WelcomeModel.dart';
import 'package:niuniu/common/router/RouteNames.dart';
import 'package:niuniu/common/service/ConfigService.dart';
import 'package:get/get.dart';

class WelcomeController extends GetxController {
  WelcomeController();

  List<WelcomeModel>? items; // 滚动集合
  int currentIndex = 0; // 当前项
  bool isShowStart = false; // 是否显示 Start
  CarouselController carouselController = CarouselController(); // slider 控制器

  // 当前位置发生改变
  void onPageChanged(int index) {
    currentIndex = index;
    isShowStart = currentIndex == 2;
    update(['slider', 'bar']);
  }

  // 去首页
  void onToMain() {
    Get.offAllNamed(RouteNames.systemMain);
  }

  // 下一页
  void onNext() {
    carouselController.nextPage();
  }

  _initData() {
    items = [
      WelcomeModel(
        image: AssetsImage.welcome_1Png,
        title: "第一页",
        desc: "第一页描述",
      ),
      WelcomeModel(
        image: AssetsImage.welcome_2Png,
        title: "第二页",
        desc: "第二页描述",
      ),
      WelcomeModel(
        image: AssetsImage.welcome_3Png,
        title: "第三页",
        desc: "第三页描述",
      ),
    ];

    update(["welcome"]);
  }

  void onTap() {}

  // @override
  // void onInit() {
  //   super.onInit();
  // }

  @override
  void onReady() {
    super.onReady();
    _initData();
    // 设置已打开
    ConfigService().setAlreadyOpen();
  }

// @override
// void onClose() {
//   super.onClose();
// }
}
